<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xalan="http://xml.apache.org/xalan"
	xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <xsl:import href="utils.xsl"/>
  <xsl:import href="fo.xsl"/>

  <xsl:template match="/">
	<xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="resume">
	<xsl:call-template name="DrawPage"/>
  </xsl:template>

  <xsl:template match="phones">
  	<xsl:call-template name="DrawRow">
  		<xsl:with-param name="labelKey" select="name()"/>
  		<xsl:with-param name="value">
  			<xsl:choose>
  				<xsl:when test="phone[@type = 'home']">
		 			<xsl:value-of select="phone[@type = 'home']"/>
		 			<xsl:text> </xsl:text>
		 			<xsl:call-template name="i18n"><xsl:with-param name="key" select="'phone.home'"/></xsl:call-template>, 
		 			<xsl:value-of select="phone[@type = 'mobile']"/>
		 			<xsl:text> </xsl:text>
		 			<xsl:call-template name="i18n"><xsl:with-param name="key" select="'phone.mobile'"/></xsl:call-template>
		  		</xsl:when>
		  		<xsl:otherwise>
		  			<xsl:value-of select="phone[@type = 'mobile']"/>
		  		</xsl:otherwise>
  			</xsl:choose>
  		</xsl:with-param>
	</xsl:call-template>
  </xsl:template>

  <xsl:template match="work">
	<xsl:call-template name="DrawRightColumn">
		<xsl:with-param name="body">
			<fo:block font-weight="bold"><xsl:value-of select="@period"/>: <xsl:value-of select="@company"/>, <xsl:value-of select="@city"/></fo:block>
			<xsl:call-template name="insertBlocksByBreaks"><xsl:with-param name="pText" select="details"/></xsl:call-template>
			<fo:block><xsl:value-of select="skills"/></fo:block>
			<fo:block><xsl:value-of select="role"/></fo:block>
		</xsl:with-param>
	</xsl:call-template>
  </xsl:template>

  <xsl:template match="project">
	<xsl:call-template name="DrawRightColumn">
		<xsl:with-param name="body">
			<fo:block font-weight="bold"><xsl:value-of select="@name"/> (<xsl:value-of select="@company"/>)</fo:block>
			<xsl:if test="@url">
				<fo:block>URL: <fo:basic-link xsl:use-attribute-sets="link">
				<xsl:attribute name="external-destination">http://<xsl:value-of select="@url"/></xsl:attribute><xsl:value-of select="@url"/></fo:basic-link>
				</fo:block>
			</xsl:if>
			<fo:block><xsl:call-template name="i18n"><xsl:with-param name="key" select="'realization'"/></xsl:call-template>: <xsl:value-of select="realization"/></fo:block>
			<fo:block><xsl:value-of select="details"/></fo:block>
		</xsl:with-param>
	</xsl:call-template>
  </xsl:template>

  <xsl:template match="institution">
	<xsl:call-template name="DrawRightColumn">
		<xsl:with-param name="body">
			<fo:block>
				<xsl:value-of select="@period"/>,
				<xsl:choose>
					<xsl:when test="@url">
						<fo:basic-link xsl:use-attribute-sets="link">
							<xsl:attribute name="external-destination">http://<xsl:value-of select="@url"/></xsl:attribute><xsl:value-of select="@name"/>
						</fo:basic-link>
					</xsl:when>
					<xsl:otherwise><xsl:value-of select="@name"/></xsl:otherwise>
				</xsl:choose>.
			</fo:block>
			<xsl:value-of select="."/>
		</xsl:with-param>
	</xsl:call-template>
  </xsl:template>

  <xsl:template match="skill">
  	<xsl:call-template name="DrawRightColumn">
  		<xsl:with-param name="body">
  			<xsl:value-of select="@header"/>: <xsl:value-of select="."/>
		</xsl:with-param>
	</xsl:call-template>
  </xsl:template>

  <xsl:template match="personal-characteristic">
  	<xsl:call-template name="DrawRow">
  		<xsl:with-param name="labelKey" select="name()"/>
		<xsl:with-param name="body">
			<xsl:for-each select="characteristic">
				<fo:block>- <xsl:value-of select="."/></fo:block>
			</xsl:for-each>
		</xsl:with-param>
	</xsl:call-template>
  </xsl:template>

  <xsl:template match="*">
  	<xsl:choose>
  		<xsl:when test="count(./*) = 0">
		    <xsl:call-template name="displaySingle"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:call-template name="displayGroup"/>
		</xsl:otherwise>
	</xsl:choose>
  </xsl:template>

</xsl:stylesheet>